<?php


/**
 * 取得品牌列表
 * @return array 品牌列表 id => name
 */
function get_brand_list(){
    $sql 		= 	'SELECT brand_id, brand_name FROM ' . 'ybr_brand' . ' ORDER BY sort_order';
    $res 		= 	M()->query($sql);

    $brand_list = 	array();
    foreach ($res AS $row){
        $brand_list[$row['brand_id']] = addslashes($row['brand_name']);
    }
    return $brand_list;
}


/*
 * 取得批发活动列表
 * @return   array
 */
function get_sql_wholesale_list(){
	
	/* 过滤条件 */
	$filter['keyword']    	= 	empty($_REQUEST['keyword']) ? '' : trim($_REQUEST['keyword']);
	if (isset($_REQUEST['is_ajax']) && $_REQUEST['is_ajax'] == 1){
		$filter['keyword'] 	= 	$filter['keyword'];
	}
	$filter['sort_by']    	= 	empty($_REQUEST['sort_by']) ? 'act_id' : trim($_REQUEST['sort_by']);
	$filter['sort_order']	= 	empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']);

	$where 					= 	"";
	if (!empty($filter['keyword'])){
		$where 				.= 	" AND goods_name LIKE '%" . Utils::mysql_like_quote($filter['keyword']) . "%'";
	}

	/* 查询 */
	$sql 					= 	"SELECT * " . "FROM " . 'ybr_wholesale' . " WHERE 1 $where " . " ORDER BY $filter[sort_by] $filter[sort_order] ";

	return $sql;
}


/**
 * 根据过滤条件获得排序的标记
 *
 * @access  public
 * @param   array   $filter
 * @return  array
 */
function sort_flag($filter){
    $flag['tag']    = 'sort_' . preg_replace('/^.*\./', '', $filter['sort_by']);
    $flag['img']    = '<img src="images/' . ($filter['sort_order'] == "DESC" ? 'sort_desc.gif' : 'sort_asc.gif') . '"/>';
    return $flag;
}




